package com.xwm93up.basic.lambdatips.Sorted;

import com.xwm93up.basic.lambdatips.Student;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * @Description: 与Stream.sorted一起使用
 * @Author: xwm93up
 * @Since: 2022/4/19 11:21
 */
public class CollectionsSortDemo1 {
    public static void main(String[] args) {
        List<Integer> numList = Arrays.asList(12, 10, 15, 8, 11);
        numList.stream().sorted(Comparator.naturalOrder()).forEach(n -> System.out.println(n + " "));
        System.out.println("\n-------------");

        List<String> strList = Arrays.asList("Varanasi", "Allahabad", "Kanpur", "Noida");
        strList.stream().sorted(Comparator.naturalOrder()).forEach(s -> System.out.println(s + " "));
        System.out.println("\n-------------");

        List<Student> studentList = Student.getStudentList();
        studentList.stream().sorted(Comparator.naturalOrder()).forEach(s -> System.out.println(s.getName() + " "));
        System.out.println("\n-------------");

        // reverseOrder 倒着排
        studentList = Student.getStudentList();
        studentList.stream().sorted(Comparator.reverseOrder()).forEach(s -> System.out.println(s.getName() + " "));
    }
}
